<?php

require_once 'Donnees/ClientData.php';

class ClientAcces  {

	public function create(ClientData  $unClientData){
		$requete = "INSERT INTO client VALUES('','".$unClientData->getNom()."','".$unClientData->getPrenom()."')";
		mysql_query($requete);
		$unClientData->setId(mysql_insert_id());
		return $unClientData;
	}
	public function read($clientData){
		//retourne ClienData
		$requete = "SELECT * FROM client WHERE id='".$clientData->getId()."'";
		$reponse = mysql_query($requete);

		$donnees = mysql_fetch_array($reponse);
		$clientData = new ClientData();
		$clientData->setId($donnees['id']);
		$clientData->setNom($donnees['nom']);
		$clientData->setPrenom($donnees['prenom']);
		return $clientData;

	}
	public function clientAccesExiste(ClientData $clientData){

		$requete = "SELECT * FROM client WHERE nom='".$clientData->getNom()."' AND prenom = '".$clientData->getPrenom()."'";

		$reponse = mysql_query($requete);
		$result = @mysql_fetch_object($reponse);
		if (empty($result)) {
			return false;
		}else return true;
	}
	public function findByNomAndPrenom(ClientData $clientData){
		$requete = "SELECT * FROM client WHERE nom='".$clientData->getNom()."' AND prenom='".$clientData->getPrenom()."'";
		$reponse = mysql_query($requete);
		$client = mysql_fetch_array($reponse);
		if(is_bool($client)) return false;
		else
		{
			$clientData = new ClientData();
			$clientData->setId($client['id']);
			$clientData->setNom($client['nom']);
			$clientData->setPrenom($client['prenom']);
			return $clientData;
		}

	}
	public function update(ClientData $unClientData){

	}

}


?>